<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>车主登录</title>
        <link rel="stylesheet" href="./css/style.css">
    </head>
	<style type="text/css">
		#mybutton{
			border:1px solid #ccc;
			background:#fff;
			color:#000;
			padding:5px 15px;
		}

	</style>
    <body>
        <header>
            <nav class="b_clear">
                <div class="nav_logo l_float">
                    
                </div>
                <div class="nav_link r_float">
                    <ul>
                        <li><a href="/user/indexs.html">返回首页</a></li>
                        <li><a href="/user/indexs.html">关于我们</a></li>
                        <li><a href="/user/indexs.html">联系我们</a></li>

                    </ul>
                </div>
            </nav>
        </header>
        <div class="container">
            <div class="login_body l_clear">
                <div class="login_form l_float">
                    <div class="login_top">
                        <img src="./imgs/logo_z.svg" alt="" class="">
                        
                        <div class="login_tags b_clear">
                            <span class="top_tag l_float active" onClick="PwdLogin()">车主登录</span>
                           
                        </div>
                    </div>
                    <div class="login_con">
                        <form action="" method="POST">
                            <div>
                                <label for="user_name">用户名</label>
                                <input type="text" name="username" id="user_name" placeholder="账号/手机号/邮箱">
                                <img src="./imgs/icons/user.svg">
                                <p class="tips hidden">请检查您的账号</p>
                            </div>
                            <div>
                                <label for="user_pwd">密码</label>
                                <input type="password" name="password" id="user_pwd" placeholder="请输入账户密码">
                                <img src="./imgs/icons/lock.svg">
                                <p class="tips hidden">请检查您的密码</p>
                            </div>
   
                            <div class="b_clear submit">

                                <input type="button" value="登录" onclick="login()"/>
                                <a href="#" class="r_float" style="padding-left: 20px;">忘记密码？</a>
								<a href="register.html" class="r_float">注册</a>
                                <p class="tips hidden">登录失败，请检查您的账户与密码或身份证号</p>
                            </div>
                        </form>   
                    </div>
                    <div class="login_con hidden">
                 
                    </div>
                    <div class="login_otherAccount">
                     
                       
                    </div>
                    
                </div>
                <div class="login_ad l_float" id="AdImg">
                
                </div>
            </div>

        </div>

        <script src="./js/login.js"></script>
		<script src="./js/new_file.js"></script>
        <script type="text/javascript" src="./js/jquery-2.1.1.min.js"></script>
    </body>
	


    <script type="text/javascript">
        $(function(){
            var per_name = localStorage.getItem("driver_name_n");
            var per_password = localStorage.getItem("driver_password");
            console.log(per_name);
            console.log(per_password);
            if (per_name != null || per_password != null) {
                $.ajax({
                    type:"post",
                    url:"/driverLogin",
                    data : JSON.stringify({driver_name_n:per_name,driver_password:per_password}),
                    contentType : "application/json;charset=UTF-8",
                    success:function(data) {
                        console.log(data);
                        if(data.status==401){
                            alert("熔断开启，系统异常");
                            window.location.href="login.html";
                            return;
                        }
                        if(data.status==200) {
                            localStorage.setItem("driver_id",data.data.driver_id);
                            localStorage.setItem("driver_name_n",data.data.driver_name_n);
                            localStorage.setItem("driver_password", data.data.driver_password);

                            window.location.href="index.html";
                            return;
                        }
                        if(data.status==500) {
                            alert("密码错误");
                            document.getElementById("user_pwd").value = "";
                            return;
                        }
                        if(data.status==null) {
                            alert("登陆异常");
                            window.location.href="login.html";
                            return;
                        }
                    }
                });
            }
        })

        function login() {
            var per_name = $("input[type='text']").val();
            var per_password = $("input[type='password']").val();

            var plist=['188','189','159','132','187','137','139','134','135','136','138','139','150','151','152','158','157','147','130','131','155','156','185','186','133','153','180','189'];
            if($('input[type=text]').val()=="" || $('input[type=text]').val().length != 11){
                alert('手机号为空或有误');
                return;

            }else if($('input[type=password]').val()==""){
                alert('请输入密码');
                return;

            }else{

                $.ajax({
                    type:"post",
                    url:"/driverLogin",
                    data : JSON.stringify({driver_name_n:per_name,driver_password:per_password}),
                    contentType : "application/json;charset=UTF-8",
                    success:function(data) {
                        console.log(data);
                        if(data.status==401){
                            alert("熔断开启，系统异常");
                            window.location.href="login.html";
                            return;
                        }
                        if(data.status==200) {
                            localStorage.setItem("driver_id",data.data.driver_id);
                            localStorage.setItem("driver_name_n",data.data.driver_name_n);
                            localStorage.setItem("driver_password", per_password);

                            window.location.href="index.html";
                            return;
                        }
                        if(data.status==500) {
                            alert("密码错误");
                            document.getElementById("user_pwd").value = "";
                            return;
                        }
                        if(data.status==null) {
                            alert("登陆异常");
                            window.location.href="login.html";
                            return;
                        }
                    }
                });

            }







        }
    </script>
</html>
